//
//  GuidePageView.swift
//  sss
//
//  Created by MAC on 2020/12/24.
//  Copyright © 2020 hrrMac. All rights reserved.
//

import UIKit

class GuidePageView: UIView {

    private let scrollView: UIScrollView = UIScrollView()
    
    // 点击回调
    var jumpBlock :(()->Void)?
    
    override init(frame: CGRect) {
        super.init(frame:frame)
        configUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func configUI(){
        addSubview(scrollView)
        scrollView.frame = self.bounds
        scrollView.isPagingEnabled = true
        scrollView.showsVerticalScrollIndicator = false
        scrollView.showsHorizontalScrollIndicator = false
        
    }
    
    ///刷新数据
    func reloadData(_ imgArr: Array<String> , titleArr: Array<String> , subTitleArr: Array<String>){
        assert(imgArr.count == titleArr.count || titleArr.count == subTitleArr.count, "资源数量不一致")
        
        let w = self.frame.size.width;
        let h = self.frame.size.height;
        
        scrollView.contentSize = CGSize.init(width: Int(w) * imgArr.count, height: 0)
        
        for index in 0..<imgArr.count {
            let pageContentView = GuidePageContentView.init(frame: self.frame)
            pageContentView.refreshData(imgArr[index], title: titleArr[index], subTitle: subTitleArr[index], pageIndex: index, allPage: imgArr.count)
            scrollView.addSubview(pageContentView)
            pageContentView.frame = CGRect.init(x: w * CGFloat(index), y: 0, width: w, height: h)
            if(index + 1 == imgArr.count){
                pageContentView.jumpBlock = jumpBlock
            }
        }
    }
    
    deinit {
        print("-----------deinit" + self.debugDescription + " \(#column) + \(#line) + \(#file) + \(#function) " + "-----------------")
    }
}
